import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:uuid/uuid.dart';

part 'user.freezed.dart';
part 'user.g.dart';

/// Type defining a user ID from Firebase.
typedef UserId = String;

@freezed
class User with _$User {
  const factory User({
    required UserId uid,
    String? email,
    String? phone,
    String? displayName,
    String? photoUrl,
    String? providerId,
    @Default(false) bool isAnonymous,
    DateTime? createdAt,
    DateTime? lastLoginAt,
  }) = _User;

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

  factory User.anonymous() => User(
        uid: const Uuid().v4(),
        isAnonymous: true,
      );
}


// /// Type defining a user ID from Firebase.
// typedef UserID = String;

// /// Simple class representing the user UID and email.
// class AppUser {
//   const AppUser({
//     required this.uid,
//     required this.email,
//   });
//   final String uid;
//   final String email;

//   @override
//   bool operator ==(Object other) {
//     if (identical(this, other)) return true;

//     return other is AppUser && other.uid == uid && other.email == email;
//   }

//   @override
//   int get hashCode => uid.hashCode ^ email.hashCode;

//   @override
//   String toString() => 'AppUser(uid: $uid, email: $email)';
// }
